package com.bytz.modules.cms.common.exception;

import com.bytz.common.api.vo.Result;
import com.bytz.common.exception.BytzBootException;
import com.bytz.modules.common.exception.BaseBizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

@RestControllerAdvice
public class CmsExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(com.bytz.common.exception.BytzBootExceptionHandler.class);

    @ExceptionHandler({BytzBootException.class})
    public Result<?> handleBytzException(BytzBootException e) {
        log.error(e.getMessage(), e);
        return Result.error("操作失败，" + e.getMessage());
    }


    @ExceptionHandler({BaseBizException.class})
    public Result<?> handleRuntimeException(BaseBizException e) {
        log.error(e.getCode()+":"+e.getMessage(), e);
        return Result.error(e.getCode(), e.getMessage());
    }

}